package com.xyy.saas.payment.cashier.core.vo;


import com.google.common.collect.Maps;
import com.xyy.saas.payment.common.Builder;
import com.xyy.saas.payment.payment.core.dto.PayDto;
import com.xyy.saas.payment.util.JSONUtils;
import com.xyy.util.StringUtil;

import javax.validation.constraints.NotEmpty;

/**
 * 收银台支付接口入参
 * @author dake
 * @date 20200325
 */
public class CashierPayVO {

    	/** 支付单号密文 */
    @NotEmpty(message = "支付单号不能为空")
    private String payNo;

	/** 支付渠道 */
    @NotEmpty(message = "支付渠道不能为空")
    private String channel;

	/** 支付模式 mini app qr pc */
    @NotEmpty(message = "支付模式不能为空")
    private String payMode;


    /** 额外信息, json字符串如选择支付宝可先忽略不传, 如选微信, {\"productId\":\"商品id\"} */
    private String mapJson;

    public PayDto convert2PayDto() {
        return Builder.of(PayDto::new)
                .with(PayDto::setPayMode, payMode)
                .with(PayDto::setPayNo, payNo)
                .with(PayDto::setChannel, channel)
                .with(PayDto::setMap, StringUtil.isEmpty(mapJson) ? Maps.newHashMap() : JSONUtils.parse2Map(mapJson, String.class, Object.class))
                .build();
    }

    public boolean notParamChecked() {
        return StringUtil.isEmpty(payMode, channel, payMode);
    }

    public String getPayNo() {
        return payNo;
    }

    public void setPayNo(String payNo) {
        this.payNo = payNo;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getPayMode() {
        return payMode;
    }

    public void setPayMode(String payMode) {
        this.payMode = payMode;
    }

    public String getMapJson() {
        return mapJson;
    }

    public void setMapJson(String mapJson) {
        this.mapJson = mapJson;
    }
}

